import type { ModuleNamespace } from 'vite/types/hot'
import type { RouteRecordRaw } from 'vue-router'

import layout from '@/layout'

const modules: ModuleNamespace[] = import.meta.glob('./modules/*.ts', {
  eager: true
}) as unknown as ModuleNamespace[]

const routesModules: RouteRecordRaw[] = []
Object.values(modules).map(item => {
  routesModules.push(...item.default)
})

console.log(routesModules)
const routes: RouteRecordRaw[] = [
  {
    path: '/sign-in',
    name: 'SignIn',
    // route level code-splitting
    // this generates a separate chunk (SignIn.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/auth/SignIn.vue'),
    meta: {
      ignoreAuth: false,
      ignoreKeepAlive: true
    }
  },
  {
    path: '/',
    name: 'Layout',
    component: layout,
    redirect: {
      name: 'Workbench'
    },
    children: [
      {
        path: 'workbench',
        name: 'Workbench',
        // route level code-splitting
        // this generates a separate chunk (Workbench.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/modules/examples/workbench')
      },
      ...routesModules
    ]
  }
]

export default routes
